<?php
/*
 * Dans le template d'affichage des forum : 
 * afficher derniers messages envoy�s (vue, notes, auteur)
 * afficher derniers sujets cr��s (messages, vues, auteur)
 * pour chaque sujet, afficher le nombre de personnes inscrites
 * pour chaque forum, idem
 */
class Forum extends Zend_Db_Table_Abstract
{	
    protected $_name = 'forums';    
	    
    public function getAll()
	{
		$userrole = Wmp_Lib::getCurrentRole();
				
		
		if($statut=='opened' || $statut=='desabled' || $statut=='closed' || $statut=='waiting')
			$forumstatut = $statut;
		
		$select = $this->select();
		$select->where('accessroles LIKE ?','%'.$userrole.'%');
		
		if(isset($forumstatut))
			$select->where('statut = ?',$forumstatut );

		$select->order('datecreated DESC');
		
		return $this->fetchAll($select);		
	}
	
	//adds or updates a forum
	public function add($data,$forumid=null)
	{
		if(is_array($data)) {			
			if(isset($forumid)) { 
				$where = $this->getAdapter()->quoteInto('id = ?', $forumid);
				$this->update($data, $where);				
			}
			else {
				$this->insert($data);				
			}			
		}
	}	
	
	public function addNote($forumid,$note)
	{		
		$forum = $this->find($forumid)->current();
		$forum->notes = $forum->notes.','.$note;
		$forum->save();
	}
	
	public function delete($forumid)
	{
		$where = $this->getAdapter()->quoteInto('id = ?', $forumid);
		$this->delete($where);
	}
	
	public function getTop($top,$count,$offset)
	{
		/*
		 *
		 // Return the 21st through 30th rows		
$count  = 10;
$offset = 20;*/
		/*switch($top)
		{
			case 'viewed' :
					$select = $this->select()
                          				->order($order)
                          				->limit($count, $offset);
					break;
			case 'noted' : 
					
					break;
			case 'nnotes'
		}
		
		$select = $this->select()->where(array('bug_status = ?' => 'NEW'))
                          ->order($order)
                          ->limit($count, $offset);*/

		return $table->fetchAll($select);
	}
	
	public function getData($forumid) 
	{
		return $this->fetchRow( $this->select()->where('id = ?', $forumid) );
	}	
	
	public function getLastMessages($forumid)
	{
		
	}
	
	public function getLastSubjects($forumid)
	{
		
	}
	
	public function getLastForums()
	{
		
	}
}
?>